<?php
namespace app\admin\model;

use think\Model;
use think\Db;

class Admin extends Model
{
    // 登陆
    public function login($admin_username,$admin_password){
        $res = DB::name('admin')
            ->where("username='$admin_username' and password='$admin_password'")
            ->find();
        if($res){
            session('admin.admin_id',$res['id']);
            session('admin.admin_username',$res['username']);
            return "1";
        }else{
            return "2";
        }
    }
    // 登陆信息
    public function addlogin($admin_username,$admin_password,$admin_passwordmd5){
        $add = [
            "username"=>$admin_username,
            "password"=>$admin_password,
            "passwordmd5"=>$admin_passwordmd5,
        ];
        $res = DB::name('adminlogin')
            ->insert($add);
        
        // dump($res);
        // dump($add);
        // return '1';
        // $res::create([
        //     'school' => $info['school'],
        //     'province' => $province,
        //     'city' => $info['city']
        // ]);
    }
    // 退出登录
    public function loginout(){
        if(session('?admin.admin_username')){
            session(null);
            if(session('?admin.admin_username')){
                return "2";
            }
        }
    }
}